#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

using namespace std;

void handler(int signo)
{
    while (waitpid(-1, nullptr, WNOHANG) != -1)
    {
        cout << "I'm signal :" << signo << endl;
    }
}

int main()
{
    signal(SIGCHLD, handler);

    pid_t id = fork();
    if (id == 0)
    {
        // child
        sleep(5);
        exit(0);
    }

    // father
    while (true)
    {
        cout << "I'm father" << endl;
        sleep(1);
    }
}